package com.kexio.security.domain.enums;

/**
 * 用户状态枚举
 * 
 * @author Kexio Team
 * @since 1.0.0
 */
public enum UserStatus {
    /**
     * 激活状态
     */
    ACTIVE(1, "激活"),
    
    /**
     * 禁用状态
     */
    DISABLED(0, "禁用"),
    
    /**
     * 锁定状态
     */
    LOCKED(2, "锁定"),
    
    /**
     * 待激活状态
     */
    PENDING(3, "待激活");

    private final Integer code;
    private final String description;

    UserStatus(Integer code, String description) {
        this.code = code;
        this.description = description;
    }

    public Integer getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 根据编码获取状态
     * @param code 状态编码
     * @return 状态枚举
     */
    public static UserStatus fromCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (UserStatus status : values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        throw new IllegalArgumentException("无效的用户状态编码: " + code);
    }

    /**
     * 检查是否为有效状态
     * @return 是否有效
     */
    public boolean isValid() {
        return this == ACTIVE || this == PENDING;
    }

    /**
     * 检查是否为激活状态
     * @return 是否激活
     */
    public boolean isActive() {
        return this == ACTIVE;
    }

    /**
     * 检查是否为禁用状态
     * @return 是否禁用
     */
    public boolean isDisabled() {
        return this == DISABLED || this == LOCKED;
    }
}
